
#pragma once

#include <string>

using namespace std;

class Solution557 {
public:
	string reverseWords(string s) {
		int len = (int)s.length();
		int i = 0;
		while (i < len)
		{
			int start = i;
			while (i<len && s[i]!=' ')
			{
				++i;
			}

			int left = start, right = i - 1;
			while (left < right)
			{
				std::swap(s[left], s[right]);
				++left;
				--right;
			}

			while (i<len && s[i] == ' ')
			{
				++i;
			}
		}
		return s;
	}
};